package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/rest"
	"gozero-demo/user/internal/config"
	"gozero-demo/user/internal/db"
	"gozero-demo/user/internal/middleware"
)

type ServiceContext struct {
	Config          config.Config
	Mysql           sqlx.SqlConn
	Redis           *redis.Redis
	TokenMiddleWare rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	newRedis := db.NewRedis(c.RedisConfig)
	return &ServiceContext{
		Config:          c,
		Mysql:           db.NewMysql(&c.MySqlConfig),
		Redis:           newRedis,
		TokenMiddleWare: middleware.NewTokenMiddleWareMiddleware(newRedis).Handle,
	}
}
